<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>

</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>管理日程</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-first">

            <div class="block-first">
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">日程日期</label>
                            <div class="layui-input-block">
                                <input type="text" id="dt" placeholder="请输入" readonly autocomplete="off" class="layui-input disabled">
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="block-generic">
                <div class="layui-form-item height_auto">
                    <div class="short_table_list" key="1">
                        <div class="opt-btn-group">
                            <div><span>日程事项</span></div>
                            <div>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                            </div>
                        </div>
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th width="45">序号</th>
                                <th style="width: 80px"><text>*</text>时间</th>
                                <th>内容</th>
                            </tr>
                            </thead>
                            <tbody class="short_table_tbody" id="list_list"></tbody>
                        </table>
                        <div class="listerror">提示：<span></span></div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<script>
    var param_dt = getQueryVariable('dt') || '';
    $("#dt").val(param_dt);

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        facade.ajax({type: 'get', url: ask_wel_guan_days, data:{dt: param_dt}}).done(function(res){
            if (res.code === 2000) {

                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td style="width: 100px"><input type="text" class="layui-input time bdate_hi"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr,1);

                var list = res.data.list;
                if(list.length > 0){
                    var str = '';
                    for (var key in list){
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td style="width: 100px"><input type="text" class="layui-input time bdate_hi" value="'+list[key].time+'"></td>';
                        str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                        str += '</tr>';
                    }
                    $("#list_list").html(str);
                }

                render_date();
                render_from();
            }
        });


        form.on('submit(add)', function(data){
            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var time = $(this).find('.time').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(!time && !explain){
                        return false;
                    }

                    if(!time){
                        throw new Error('第'+index+'行，请选择时间');
                    }
                    if(!explain){
                        throw new Error('第'+index+'行，请输入内容');
                    }

                    list.push({
                        dt:param_dt,
                        time:time,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;

            data.field.dt = param_dt;
            facade.ajax({url: ask_wel_guan_days, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    $("#days_date .shi", parent.document).find('.active').click();
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });


</script>
</body>
</html>
